/**
 * 神州信息(2012)
 */
package net.abbp.report.view.cell.editor;

import java.awt.Component;

import net.abbp.report.context.ReportContext;
import net.abbp.report.model.Cell;
import net.abbp.report.model.ReportModel;
import net.abbp.report.view.grid.Grid;

import com.reportgear.core.swing.pane.base.JBaseDialog;

/**
 * 子报表单元格编辑器
 * 
 * @version 1.0
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since ABBP 1.0
 * 
 *        <pre>
 * 历史：
 *      建立: 2012-7-22 lexloo
 * </pre>
 */
public class SubReportCellEditor extends AbstractCellEditor {
    private ReportModel reportModel;

    @Override
    public Component getCellEditorComponent(Grid grid, Cell cell) {
        SubReportDesignPane editorPane = new SubReportDesignPane();
        ReportContext.INSTANCE.pushCurrentView();
        ReportContext.INSTANCE.setCurrentView(editorPane.getGridView());

        Object o = cell.getValue();

        if (o instanceof ReportModel) {
            this.reportModel = (ReportModel) o;
        }

        editorPane.populate(this.reportModel);
        int result = editorPane.showDialog(grid);

        if (result == JBaseDialog.RESULT_OK) {
            this.reportModel = editorPane.update();
        }

        // 恢复当视图
        ReportContext.INSTANCE.popCurrentView();

        return null;
    }

    @Override
    public Object getCellEditorValue() {
        return reportModel;
    }

}
